﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数字千分位函数</title>
    <script type="text/javascript" language="JavaScript">
        function millon()
        {
            var s=parseFloat(myNum.value); //获取小数型数据
            s+="";
            if(s.indexOf(".")==-1) s+=".0";//如果没有小数点，在后面补个小数点和0
            if(/\.\d$/.test(s)) s+="0";   //正则判断
            while(/\d{4}(\.|,)/.test(s))  //符合条件则进行替换
                s=s.replace(/(\d)(\d{3}(\.|,))/,"$1,$2");//每隔3位添加一个，
            alert(s);
        }       
    </script>
</head>
<body>
<input type="text" name="myNum" value="1234567890.08"><input type="button" value="millon" onclick="millon()">
</body>
</html>